#
#
# Define share variable
#
#
.PHONY: install clean
MY_COM_INC := $(TOP)/include

ifeq ($(release), yes)
DEBUG_FLAG := -O2 -DNDEBUG
else
DEBUG_FLAG := -g
endif

CC      ?= g++
CXX     ?= g++
CFLAGS  += $(DEBUG_FLAG) -Wall -fPIC
LDFLAGS += $(DEBUG_FLAG) -lstdc++
EXTRA_CFLAGS  += -I$(TOP)/include
EXTRA_LDFLAGS +=  

# Common build rules
%.o: %.cpp
	$(CXX) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
%.o: %.c
	$(CC)  $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@


# Build dynamic libarary
ifdef L_TARGET
$(L_TARGET): $(OBJECTS)
	$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $(L_TARGET) $(OBJECTS)

$(OBJECTS): $(BASE_HEAD_FILES)

install:
	@-cp -f $(L_TARGET) $(MY_LIB_DIR)
endif

# Buid executable bin
ifdef EXE_TARGET
$(EXE_TARGET): $(OBJECTS)
	$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $(EXE_TARGET) $(OBJECTS)
$(OBJECTS): $(BASE_HEAD_FILES)

install:
	@-cp -f $(EXE_TARGET) $(MY_BIN_DIR)
endif

# Clean
clean:
	@-rm -f $(L_TARGET) $(EXE_TARGET) *.o

export LD_LIBRARY_PATH=$(TOP)/lib
